-module(sms).
-export([send/3,start/0,test/0]).
start() ->
	inets:start().
	
send(post, MS,Content) ->
	URL = "http://124.172.250.160/WebService.asmx/mt",
	Data = lists:flatten(io_lib:format("Sn=lian&Pwd=888888&mobile=~s&content=~s",[MS,yaws_api:url_encode((Content))])),
	Request = {URL,[{"Content-Length",length(Data)}],"application/x-www-form-urlencoded",Data},
	io:format("~p~n",[Request]),
	httpc:request(post,Request,[],[],default);

send(get, MS, Content) ->
	URL = "http://sms.4006555441.com/webservice.asmx/",
	Request = lists:flatten(io_lib:format("~sSendSMS?Sn=lian&Pwd=888888&mobile=~s&content=~s&stime=~s",[URL,MS,
			yaws_api:url_encode(Content),yaws_api:url_encode(local_time_str())])),
	io:format("~s",[Request]),
	httpc:request(Request).

local_time_str() ->
	{{Year,Month,Day},{Hour,Min,Sec}} = calendar:local_time(),
	lists:flatten(
		io_lib:format("~B-~B-~B ~B:~B:~B",[Year,Month,Day,Hour,Min+1,Sec])
	).

test() ->
	Content = template:get(sms_template),
	send(post,"13570023732",Content).